package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class FindOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("查找图书");
        System.out.print("请输入书名-->");
        String name = scanner.nextLine();
        Book book = null;
        int i = 0;
        for (i = 0; i < bookList.getBookNum(); i++) {
            book = bookList.getBook(i);
            if(book.getName().equals(name)) {
                break;
            }
        }
        if(i == bookList.getBookNum()) {
            System.out.println("查无此书");
        } else {
            System.out.println(book.toString());
            System.out.println("查找成功");
        }
    }
}
